package com.foreknow.util;

import com.foreknow.model.Business;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import java.util.List;

/**
 * @author ttc
 * 这个类根据data值和表头coulum制动态表
 */
public class PropertyJtable {
    private static PropertyJtable jtable = null;
    private DefaultTableModel model = new DefaultTableModel();

    private PropertyJtable() {

    }

    public static PropertyJtable getJtable() {
        if (jtable == null) {
            jtable = new PropertyJtable();
        }
        return jtable;
    }

    /**
     * 根据data，coulum制作一个新动态表
     *
     * @Object data
     * @String column
     * @JTable
     */
    public JTable newJtable(Object[][] data, String[] column) {
        model.setDataVector(data, column);
        JTable jtable = new JTable(model);
        return jtable;
    }

    /**
     * 更新动态表
     *
     * @Object data
     * @String column
     */
    public void update(Object[][] data, String[] column) {
        model.setDataVector(data, column);
    }


    public Object[][] data(List<Object> list) {
        Object data[][] = new Object[list.size()][7];
        for (int i = 0; i < list.size(); i++) {
            Business u = new Business();
            u = (Business) list.get(i);
            data[i][0] = u.getBusinessId();
            data[i][1] = u.getPassword();
            data[i][2] = u.getBusinessName();
            data[i][3] = u.getBusinessAddress();
            data[i][4] = u.getBusinessExplain();
            data[i][5] = u.getStarPrice();
            data[i][6] = u.getDeliveryPrice();
        }
        return data;
    }
}
